#@layout()
#define main()
<link href="#(base)/fslayui/plugins/eleTree/eleTree.css" rel="stylesheet"/>
<div class="layui-card">
    <div class="layui-card-body">
        <div class="eleTree ele1"></div>
        <hr/>
        <div class="layui-form-item" style="text-align: center;">
            <button id="updaterole" class="layui-btn">提交</button>
            <button type="button" class="layui-btn layui-btn-primary" function="close">关闭</button>
        </div>
    </div>
</div>
<script>
    var base = '#(base)';
    var roleid = '#(roleid)';

    layui.use(['jquery','eleTree'],function () {
        var $ = layui.jquery;
        var eleTree = layui.eleTree;

        var elet = eleTree.render({
            url: base+'/menu/getMenutree?roleid='+roleid,
            method: 'post',
            //where: {roleid:roleid},
            contentType:'application/json',
            elem: '.ele1',
            autoExpandParent: true,
            showCheckbox: true,
            defaultExpandAll: true,
            request: {
                name: "menuName",
                key: "menuId",
                children: "children",
                checked: "checked",
                disabled: "disabled",
                isLeaf: "isLeaf"
            },
            response: {
                statusName: "code",
                statusCode: 0,
                dataName: "data"
            }
        });

        $("#updaterole").click(function () {
            var checkeddata = elet.getChecked(false,true);
            var jsonstr = new Array();
            for(var i=0;i<checkeddata.length;i++){
                jsonstr.push(checkeddata[i].menuId);
            }
            console.log(checkeddata);
            $.ajax({
                type:"POST",
                url:base+"/role/accredit",
                data:{
                    'roleid':roleid,
                    'menuIds':jsonstr
                },
                dataType:"json",
                success:function(data){
                    layer.alert(data.errorInfo, function(index){
                        //do something
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        layer.close(index);
                    });

                },
                error:function(jqXHR){
                    layer.alert("发生错误："+jqXHR.status, function(index){
                        //do something
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        layer.close(index);
                    });
                    console.log("发生错误："+jqXHR.status);
                }
            });
        })



    })
</script>

#end